

import axios from 'axios'
/**  项目所有的请求 */
let base='/proxyApi';

export default {
  //用户登录
  login(params) {return httPost(`${base}/login`, params)},

  //获取图片验证码
  getCaptcha(params) {return httpGet(`${base}/captcha`, params)},
  getUserListPage(params) { return httpGet(`${base}/user/listpage`,  params )},
  removeUser(params) { return httpGet(`${base}/user/remove`,  params )},
  editUser(params) { return httpGet(`${base}/user/edit`,  params )},
  addUser(params) { return httpGet(`${base}/user/list`,  params )},
  getUserList(params) { return httpGet(`${base}/user/add`,  params )},
}




/**  axios基础配置 */
export const http = axios.create({
  timeout: 1000 * 30,
  withCredentials: true,
  headers: {
    'Content-Type': 'application/json; charset=utf-8'
  }
})



/** axios封装请求get,post方法 */
export function httpPost(url, params) {
  console.log('%c请求参数:','color: #20a0ff;',params);
  console.log('%c请求接口地址:','color: #20a0ff;',url);
  return new Promise((resolve, reject) => {
    http.post(url, params)
      .then(response => {
        resolve(response.data);//成功后返回结果
      }, err => {
        reject(err);
        console.log('%c请求接口:','color: #ff4949;',url);
      })
      .catch((error) => {
        reject(error);
      })
  })
}

export function httpGet(url, params) {
  return new Promise((resolve, reject) => {
    http.get(url, params).then(response => {
      debugger;
        console.log('%c请求成功','color: #13ce66;');
        console.log('%c请求接口:','color: #13ce66;');
        console.log(url);
        resolve(response.data);//成功后返回结果
      }, err => {
        reject(err);
      })
      .catch((error) => {
        reject(error);
      })
  })
}

